package Top_Interview_Questions.Hash_Table;

import java.util.HashMap;

/**
 * @Author: 吕庆龙
 * @Date: 2020/3/10 14:00
 * <p>
 * 功能描述:
 */
public class _0387 {

    public int firstUniqChar(String s) {
        HashMap<Character, Integer> count = new HashMap<Character, Integer>();
        int n = s.length();

        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);
            count.put(c, count.getOrDefault(c, 0) + 1);
        }

        for (int i = 0; i < n; i++) {
            if (count.get(s.charAt(i)) == 1)
                return i;
        }
        return -1;
    }
}
